import axios from "axios";

const service = axios.create({
    timeout:10000,
    baseURL:process.env.VUE_APP_BASE_URL
})


service.interceptors.request.use((config) => {
    config.headers["Content-Type"] = config.headers["Content-Type"] ? config.headers["Content-Type"] : 'application/x-www-form-urlencoded'
    return config
},error => {
    return Promise.reject(error)
})

service.interceptors.response.use((res) => {
    let {data:response} = res // 将返回的信息直接拆解
    switch (response.code){
        case 400:
            return  Promise.reject(new Error(response.message || "Error"))
    }
    return response
})


export default service
